home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / lib.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  3.4 KB  |  130 lines

  1. package lib;
  2.  
  3. use vars qw(@ORIG_INC);
  4. use Config;
  5.  
  6. my $archname = $Config{'archname'};
  7.  
  8. @ORIG_INC = @INC;    # take a handy copy of 'original' value
  9.  
  10.  
  11. sub import {
  12.     shift;
  13.     foreach (reverse @_) {
  14.     next unless defined($_);
  15.     if ($_ eq '') {
  16.         require Carp;
  17.         Carp::carp("Empty compile time value given to use lib");
  18.     }
  19.     unshift(@INC, $_);
  20.     if (-d "$_/$archname") {
  21.         unshift(@INC, "$_/$archname")    if -d "$_/$archname/auto";
  22.         unshift(@INC, "$_/$archname/$]") if -d "$_/$archname/$]/auto";
  23.     }
  24.     }
  25. }
  26.  
  27.  
  28. sub unimport {
  29.     shift;
  30.     my $mode = shift if $_[0] =~ m/^:[A-Z]+/;
  31.  
  32.     my %names;
  33.     foreach(@_) {
  34.     ++$names{$_};
  35.     ++$names{"$_/$archname"} if -d "$_/$archname/auto";
  36.     }
  37.  
  38.     if ($mode and $mode eq ':ALL') {
  39.     @INC = grep { !exists $names{$_} } @INC;
  40.     } else {
  41.     @INC = grep { --$names{$_} < 0   } @INC;
  42.     }
  43. }
  44.  
  45. 1;
  46. __END__
  47.  
  48. =head1 NAME
  49.  
  50. lib - manipulate @INC at compile time
  51.  
  52. =head1 SYNOPSIS
  53.  
  54.     use lib LIST;
  55.  
  56.     no lib LIST;
  57.  
  58. =head1 DESCRIPTION
  59.  
  60. This is a small simple module which simplifies the manipulation of @INC
  61. at compile time.
  62.  
  63. It is typically used to add extra directories to perl's search path so
  64. that later C<use> or C<require> statements will find modules which are
  65. not located on perl's default search path.
  66.  
  67. =head2 ADDING DIRECTORIES TO @INC
  68.  
  69. The parameters to C<use lib> are added to the start of the perl search
  70. path. Saying
  71.  
  72.     use lib LIST;
  73.  
  74. is I<almost> the same as saying
  75.  
  76.     BEGIN { unshift(@INC, LIST) }
  77.  
  78. For each directory in LIST (called $dir here) the lib module also
  79. checks to see if a directory called $dir/$archname/auto exists.
  80. If so the $dir/$archname directory is assumed to be a corresponding
  81. architecture specific directory and is added to @INC in front of $dir.
  82.  
  83. If LIST includes both $dir and $dir/$archname then $dir/$archname will
  84. be added to @INC twice (if $dir/$archname/auto exists).
  85.  
  86. =head2 DELETING DIRECTORIES FROM @INC
  87.  
  88. You should normally only add directories to @INC.  If you need to
  89. delete directories from @INC take care to only delete those which you
  90. added yourself or which you are certain are not needed by other modules
  91. in your script.  Other modules may have added directories which they
  92. need for correct operation.
  93.  
  94. By default the C<no lib> statement deletes the I<first> instance of
  95. each named directory from @INC.  To delete multiple instances of the
  96. same name from @INC you can specify the name multiple times.
  97.  
  98. To delete I<all> instances of I<all> the specified names from @INC you can
  99. specify ':ALL' as the first parameter of C<no lib>. For example:
  100.  
  101.     no lib qw(:ALL .);
  102.  
  103. For each directory in LIST (called $dir here) the lib module also
  104. checks to see if a directory called $dir/$archname/auto exists.
  105. If so the $dir/$archname directory is assumed to be a corresponding
  106. architecture specific directory and is also deleted from @INC.
  107.  
  108. If LIST includes both $dir and $dir/$archname then $dir/$archname will
  109. be deleted from @INC twice (if $dir/$archname/auto exists).
  110.  
  111. =head2 RESTORING ORIGINAL @INC
  112.  
  113. When the lib module is first loaded it records the current value of @INC
  114. in an array C<@lib::ORIG_INC>. To restore @INC to that value you
  115. can say
  116.  
  117.     @INC = @lib::ORIG_INC;
  118.  
  119.  
  120. =head1 SEE ALSO
  121.  
  122. FindBin - optional module which deals with paths relative to the source file.
  123.  
  124. =head1 AUTHOR
  125.  
  126. Tim Bunce, 2nd June 1995.
  127.  
  128. =cut
  129.  
  130.